package com.lzf.router;

import com.lzf.model.SmsInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

public class SmsRouter {
    /*
    * 短信网关对象，通过volatile修饰来保证其他线程的可见性
    * */
    private static volatile SmsRouter intance=new SmsRouter();

    /*
    * 短信服务商信息的map，key表示服务上的优先级
    * */
    private final Map<Integer, SmsInfo> smsInfoRouteMap;

    /*
    * 初始化网关路由信息
    * */
    public SmsRouter(){
        //从数据库中维护的路由信息加载到jvm内存中
        this.smsInfoRouteMap=this.loadSmsInfoRouteMapFromDb();

    }

    public static void main(String[] args) {
        List<Object> list=new CopyOnWriteArrayList();
        list.add("aaaa");
        list.add("cccc");
        System.out.println(list);

    }
    private Map<Integer, SmsInfo> loadSmsInfoRouteMapFromDb() {
        Map<Integer,SmsInfo> routerMap=new HashMap<>();
        routerMap.put(1,new SmsInfo("aliyun.com",180L));
        routerMap.put(2,new SmsInfo("cloud.tencent.com",181L));
        routerMap.put(3,new SmsInfo("cloud.baidu.com",182L));
        return routerMap;
    }

}
